package com.hky.front_end_monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hky.front_end_monitor.entity.SysHttpRecord;
import com.hky.front_end_monitor.service.SysHttpRecordService;
import com.hky.front_end_monitor.mapper.SysHttpRecordMapper;
import com.hky.front_end_monitor.utils.NumberUtils;
import com.hky.front_end_monitor.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* @author hello
* @description 针对表【sys_http_record】的数据库操作Service实现
* @createDate 2022-08-01 20:14:52
*/
@Service
public class SysHttpRecordServiceImpl extends ServiceImpl<SysHttpRecordMapper, SysHttpRecord>
    implements SysHttpRecordService{

    @Override
    public boolean storeHttpRecord(String uuid, Map map) {
        String userId = StringUtils.caseToString(map.get("userId"));
        SysHttpRecord httpRecord = new SysHttpRecord();
        httpRecord.setUserId(userId);
        httpRecord.setHttpRecordId(uuid);
        Map data =(Map) ((Map) map.getOrDefault("meta", map)).getOrDefault("metrics", map);
        httpRecord.setUrl(StringUtils.caseToString(data.getOrDefault("url", map)));
        httpRecord.setMethod(StringUtils.caseToString(data.getOrDefault("method", map)));
        httpRecord.setBody(StringUtils.caseToString(data.getOrDefault("body", map)));
        httpRecord.setRequestTime(NumberUtils.toLong(data.getOrDefault("requestTime", map)));
        httpRecord.setResStatus(NumberUtils.toInteger(data.getOrDefault("status", map)));
        httpRecord.setResStatusText(StringUtils.caseToString(data.getOrDefault("statusText", map)));
        httpRecord.setResponse(StringUtils.caseToString(data.getOrDefault("response", map)));
        httpRecord.setResponseTime(NumberUtils.toLong(data.getOrDefault("responseTime", map)));
        return this.save(httpRecord);
    }
}




